﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Pharmacy_management_system
{
    public partial class DianZiYaoLi : Form
    {
        public DianZiYaoLi()
        {
            InitializeComponent();
        }

        private void DianZiYaoLi_Load(object sender, EventArgs e)
        {
            //由遗嘱明细传过去的字段
            label15.Text = Form1.dept01;
            label8.Text = Form1.dept01;
            this.timer1.Interval = 100;
            this.timer1.Enabled = true;
            label10.Text = DateTime.Now.ToShortDateString();//显示时间
            label100.Text = Form1.dianzi1;
            label129.Text = Form1.dianzi2;
            label127.Text = Form1.dianzi3;
            label125.Text = Form1.dianzi4;
            label109.Text = Form1.dianzi5;
            label110.Text = Form1.dianzi6;
            label121.Text = Form1.dianzi7;
            label119.Text = Form1.dianzi8;
            label112.Text = Form1.dianzi9;
            label2.Text = Form1.dianzi10;
            label107.Text = Form1.dianzi11;
            label104.Text = Form1.dianzi12;
            label106.Text = Form1.dianzi13;
            label108.Text = Form1.dianzi14;
            label113.Text = Form1.dianzi15;
            textBox2.Text = Form1.dianzi16;
            textBox3.Text = Form1.dianzi17;
           

            //由数据库提取出来的字段
            string strsql = "select inp_no,jwbs,jwyys,gms,grjzs,lczdyd,bszztz,fzjc,zlyz,zyzlyw,ywzlrz from dianziyaoli where inp_no='" + Form1.dianzi1 + "'";
            SqlConnection conn = new SqlConnection(SQL.constr);
            conn.Open();
            SqlDataAdapter hhh = new SqlDataAdapter(strsql, SQL.constr);
            DataSet dtt = new DataSet();
            hhh.Fill(dtt);
            for (int i = 0; i < dtt.Tables[0].Rows.Count; i++)
            {
                label100.Text = dtt.Tables[0].Rows[i].ItemArray[0].ToString();//住院
                richTextBox2.Text = dtt.Tables[0].Rows[i].ItemArray[1].ToString();//病人名
                richTextBox1.Text = dtt.Tables[0].Rows[i].ItemArray[2].ToString();//性别
                richTextBox3.Text = dtt.Tables[0].Rows[i].ItemArray[3].ToString();//出生日期
                richTextBox4.Text = dtt.Tables[0].Rows[i].ItemArray[4].ToString();//年龄
                richTextBox5.Text = dtt.Tables[0].Rows[i].ItemArray[5].ToString();//身高
                richTextBox6.Text = dtt.Tables[0].Rows[i].ItemArray[6].ToString();//体重
                richTextBox7.Text = dtt.Tables[0].Rows[i].ItemArray[7].ToString();//身份证
                richTextBox8.Text = dtt.Tables[0].Rows[i].ItemArray[8].ToString();//民族
                richTextBox9.Text = dtt.Tables[0].Rows[i].ItemArray[9].ToString();//籍贯
                richTextBox10.Text = dtt.Tables[0].Rows[i].ItemArray[10].ToString();//工作单位

            }
            conn.Close();

        }

        private void button1_Click(object sender, EventArgs e)
        {



        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = DateTime.Now.ToShortDateString();//显示时间
        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }
        #region 保存电子药历
        private void button1_Click_1(object sender, EventArgs e)
        {
            string hh1 = "insert into dianziyaoli(inp_no,jwbs,jwyys,gms,grjzs,lczdyd,bszztz,fzjc,zlyz,zyzlyw,ywzlrz,qianming,writetime) values  ('" +
                label100.Text + "','" + richTextBox2.Text + "','" + richTextBox1.Text + "','" + richTextBox3.Text + "','" + richTextBox4.Text + "','" + richTextBox5.Text + "','" + richTextBox6.Text + "','" +
                richTextBox7.Text + "','" + richTextBox8.Text + "','" + richTextBox9.Text + "','" + richTextBox10.Text + "','" + label8.Text + "','" + label10.Text + "')";
            using (SqlConnection conn1 = new SqlConnection(SQL.constr))
            {
                int bianliang1;
                conn1.Open();
                SqlCommand cmd = new SqlCommand(hh1, conn1);
                bianliang1 = cmd.ExecuteNonQuery();

            }
        }
        #endregion
        #region 修改电子药历
        private void button2_Click_1(object sender, EventArgs e)
        {
            string sql = "update dianziyaoli set inp_no='" + label100.Text + "',jwbs='" + richTextBox2.Text + "',jwyys='" + richTextBox1.Text + "',gms='" +
                        richTextBox3.Text + "', grjzs='" + richTextBox4.Text + "',lczdyd= '" + richTextBox5.Text + "',bszztz='" + richTextBox6.Text + "',fzjc='" +
                        richTextBox7.Text + "',zlyz='" + richTextBox8.Text + "', zyzlyw='" + richTextBox9.Text + "',ywzlrz='" + richTextBox10.Text + "',qianming='" + label8.Text + "',writetime='" + label10.Text + "' ";
            using (SqlConnection conn1 = new SqlConnection(SQL.constr))
            {
                int bianliang5;
                conn1.Open();
                SqlCommand cmd = new SqlCommand(sql, conn1);
                bianliang5 = cmd.ExecuteNonQuery();
            }
            MessageBox.Show("修改成功");
        }
        #endregion

        private void panel5_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label12_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click_2(object sender, EventArgs e)
        {

        }

        private void button2_Click_2(object sender, EventArgs e)
        {

        }
        #region 保存电子药历09
        //保存电子药历
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            string hh1 = "insert into dianziyaoli(inp_no,jwbs,jwyys,gms,grjzs,lczdyd,bszztz,fzjc,zlyz,zyzlyw,ywzlrz,qianming,writetime,case_id) values  ('" +
               label100.Text + "','" + richTextBox2.Text + "','" + richTextBox1.Text + "','" + richTextBox3.Text + "','" + richTextBox4.Text + "','" + richTextBox5.Text + "','" + richTextBox6.Text + "','" +
               richTextBox7.Text + "','" + richTextBox8.Text + "','" + richTextBox9.Text + "','" + richTextBox10.Text + "','" + label8.Text + "','" + label10.Text + "','"+DangQianHang.cc+"')";
            using (SqlConnection conn1 = new SqlConnection(SQL.constr))
            {
                int bianliang1;
                conn1.Open();
                SqlCommand cmd = new SqlCommand(hh1, conn1);
                bianliang1 = cmd.ExecuteNonQuery();
            }
            MessageBox.Show("保存");
           
        #endregion
        }
        #region 修改电子药历09
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            string sql = "update dianziyaoli set inp_no='" + label100.Text + "',jwbs='" + richTextBox2.Text + "',jwyys='" + richTextBox1.Text + "',gms='" +
                       richTextBox3.Text + "', grjzs='" + richTextBox4.Text + "',lczdyd= '" + richTextBox5.Text + "',bszztz='" + richTextBox6.Text + "',fzjc='" +
                       richTextBox7.Text + "',zlyz='" + richTextBox8.Text + "', zyzlyw='" + richTextBox9.Text + "',ywzlrz='" + richTextBox10.Text + "',qianming='" + label8.Text + "',writetime='" + label10.Text + "',case_id='"+DangQianHang.cc+"'  where case_id='"+DangQianHang.cc+"'    ";
            using (SqlConnection conn1 = new SqlConnection(SQL.constr))
            {
                int bianliang5;
                conn1.Open();
                SqlCommand cmd = new SqlCommand(sql, conn1);
                bianliang5 = cmd.ExecuteNonQuery();
            }
            MessageBox.Show("修改成功");
        }
        #endregion

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
